//index.js
//获取应用实例
var app = getApp();

Page({
    data: {
        scrollTop: {
            scroll_top: 0,
        },
        //首页顶部加载中是否显示
        topjiazai:false,
        showPulldown: false,
        isFixed: false,
        isshow_subsidy: true,
        minprice: '',
        maxprice: '',
        redTriangle: false,
        isShow0: false,
        isShow1: false,
        isShow2: false,
        sort: 0,
        cname: "",
        sortName: "默认",
        currentTab: 0,
        currentTab2: 0,
        hiddenLoading: false,
        indicatorDots: true,
        autoplay: true,
        interval: 3000,
        from_uid: 0,
        nickname: '',
        memberid: 0,
        datalock: false,
        uri: "list",
        searchkey: "",
        showAnimation: false,
        globalset: {

        },
        homeskinid: -1,
        duration: 100,
        banner: [
          1,2,3
        ],
        commodity: [
          1,2,3,4
        ],
        goodCarousel: [

        ],
        goodCarousel2: [

        ],
        imgmenuPage:[
          [
              1,2,3,4
          ],
          [
            1, 2, 3, 4
          ], [
            1, 2, 3, 4
          ],
          
        ],
        
        helpmenu: [
            {
                "img": '../../images/activity3.png',
                "name": '省钱看这里',
                "url": '../savemoney-help/index'
            },
            {
                "img": '../../images/activity4.png',
                "name": '赚钱看这里',
                "url": '../makemoney-help/index'
            }
        ],
        activitymenu: [

        ],
    },
    onPullDownRefresh: function () {
        var $that = this;
        console.log("进入下拉");
        $that.setData({
            topjiazaia: true
        })
        
        $that.getGlobalSet();
        wx.showLoading({
            title: '加载中',
        })
        wx.stopPullDownRefresh();
        setTimeout(function () {
            wx.hideLoading()
        }, 2000)
        setTimeout(function () {
          
          $that.setData({
              topjiazaia:false
          }) 
        }, 2000)
    },
    onLoad: function (options) {

      

        if (typeof options != "undefined" && typeof options.partner != "undefined") {
            //wx.setNavigationBarTitle({
            //    title:"我的伙伴"//页面标题
            //});
            wx.navigateTo({
                url: '../partnerIndex/index',
            });
            //return;
        }


        //app.setTabBar();
        var $this = this;
        //扫二维码进来的推荐人ID获取
        if (typeof options != "undefined" && typeof options.scene != "undefined") {
            wx.setStorage({
                key: "from_uid",
                data: options.scene
            });
            this.setData({
                from_uid: options.scene,
                datalock: false
            });

        }



        if (typeof options != "undefined" && typeof options.from_uid != "undefined") {
            wx.setStorage({
                key: "from_uid",
                data: options.from_uid
            });
            this.setData({
                from_uid: options.from_uid,
                datalock: false
            });
        }
        if (typeof options != "undefined" && typeof options.from_nickname != 'undefined' && options.type == 1) {
            /*
            wx.setNavigationBarTitle({
              title: options.from_nickname + '的小店'//页面标题
            });
            */
            /*
            this.setData({
              homeskinid: options.homeskinid,
              datalock: false
            });
            */
        }
        wx.getStorage({
            key: "memberinfo",
            success: function (res) {
                if (typeof res.data.from_nickname != 'undefined' && res.data.from_nickname != '' && res.data.from_nickname != '无') {
                    wx.setNavigationBarTitle({
                        title: res.data.from_nickname + '的小店'//页面标题
                    });
                }

                if (typeof res.data.nickname != 'undefined' && res.data.nickname != '' && res.data.type == 1) {
                    wx.setNavigationBarTitle({
                        title: res.data.nickname + '的小店'//页面标题
                    });
                    $this.setData({
                        homeskinid: res.data.homeskinid,
                        datalock: false
                    });
                }
                if (typeof res.data.from_shopname != 'undefined' && res.data.from_shopname != '' && res.data.from_shopname != '无') {
                    wx.setNavigationBarTitle({
                        title: res.data.from_shopname//页面标题
                    });
                }
                if (typeof res.data.shopname != 'undefined' && res.data.shopname != '' && res.data.type == 1) {
                    wx.setNavigationBarTitle({
                        title: res.data.shopname//页面标题
                    });
                    $this.setData({
                        homeskinid: res.data.homeskinid,
                        datalock: false
                    });
                }


            }
        });
        this.getGlobalSet();
        //控制弹窗的函数
        this.showTanchuang();


        //获取缓存中的searchkey
        //判断剪贴班中是否有内容

        //判断是否先显示补助



    },
    initIndex: function () {
        var $this = this;
        $this.sign();
        $this.judgeTem();
        $this.goodList(1);
        //$this.goodList(1, "limittime", '', 0);
        //$this.goodList(1, "realtime", '', 0);

        var memberinfo = wx.getStorageSync('memberinfo');
        $this.setData({ memberinfo: memberinfo });
        var globalset = wx.getStorageSync('globalset');
        $this.setData({
            commission: 0,
            datalock: false
        });
        //计算总的佣金比例
        var total_commission = 0;
        if (globalset.memberlevel != undefined && globalset.memberlevel.length != undefined) {
            for (var i = 0; i < globalset.memberlevel.length; i++) {

                //当前会员类型的等级佣金比例
                if (globalset.memberlevel[i].type == memberinfo.type && globalset.memberlevel[i].name == memberinfo.level) {
                    total_commission = parseFloat(globalset.memberlevel[i].myteam_credit2) + parseFloat(globalset.memberlevel[i].myleader1_credit2) + parseFloat(globalset.memberlevel[i].myleader2_credit2);
                    //换成只取1级佣金的比例
                    total_commission = parseFloat(globalset.memberlevel[i].myteam_credit2);

                    $this.setData({
                        commission: total_commission,
                        datalock: false
                    });

                }
            }
        }
        if (memberinfo.type == 0) {
            if (globalset.isopen_subsidy == 0) {
                $this.setData({
                    isshow_subsidy: false
                });
            }

            total_commission = parseFloat(globalset.subsidy);
            $this.setData({
                commission: total_commission,
                datalock: false
            });
        }

        if (globalset.isshow_subsidy == 0) {
            $this.setData({
                isshow_subsidy: false
            });
        }
    },
    getGlobalSet: function () {
        var $this = this;
        app.util.request({
            url: 'entry/wxapp/Global',
            showLoading: false,
            data: {
                "m": 'nets_haojk'
            },
            method: 'post',
            success: function (response) {
                var globalset = response.data.data;
                console.log(globalset);
                $this.setData({
                    hiddenLoading: true
                });
                $this.setData({
                    globalset: globalset,
                    homeskinid: globalset.homeskinid
                });
                wx.setStorage({
                    key: "globalset",
                    data: globalset
                });
                //banner
                var banner_str = globalset.banner;
                var banner_json = JSON.parse(banner_str);
                if (banner_json != undefined && banner_json.list != null && banner_json.list != undefined && typeof banner_json.list != undefined && banner_json.list != null && banner_json.list != '') {
                    $this.setData({
                        banner: banner_json.list,
                        datalock: false
                    });
                }
                //图标菜单
                var newhead_menu_json = [];
                var head_menu_str = globalset.head_menu;
                var head_menu_json = JSON.parse(head_menu_str);


                if (head_menu_json != undefined && head_menu_json.list != null && head_menu_json.list != undefined && typeof head_menu_json.list != undefined && head_menu_json.list != null && head_menu_json.list != '') {
                    var menulen = head_menu_json.list.length;
                    for (var i = 0; i < 8; i++) {
                        newhead_menu_json.push(head_menu_json.list[i])
                    }


                    $this.setData({
                        imgmenu: newhead_menu_json,
                        datalock: false

                    });


                    var imgmenu2 = new Array();
                    for (var i = 8; i < 16; i++) {
                        imgmenu2.push(head_menu_json.list[i]);
                    }
                    $this.setData({
                        imgmenu2: imgmenu2,
                        datalock: false
                    });

                    $this.setData({
                        imgmenuAll: head_menu_json.list,
                        datalock: false
                    });


                    var imgmenu22 = new Array();
                    for (var i = 16; i < menulen; i++) {
                        imgmenu22.push(head_menu_json.list[i]);
                    }
                    $this.setData({
                        imgmenu22: imgmenu22,
                        datalock: false
                    });
                    var imgmenu222 = new Array();
                    for (var i = 24; i < menulen; i++) {
                        imgmenu222.push(head_menu_json.list[i]);
                    }
                    $this.setData({
                        imgmenu222: imgmenu222,
                        datalock: false
                    });
                }
                //图片魔方菜单
                var picture_menu_str = globalset.picture_menu;
                var picture_menu_json = JSON.parse(picture_menu_str);
                var picture_menu = new Array();
                var pmenu = new Object();

                if (picture_menu_json != undefined && typeof picture_menu_json.list != undefined && picture_menu_json.list != null && picture_menu_json.list != null && picture_menu_json.list.length >= 4) {
                    pmenu.img1 = typeof picture_menu_json.list[0].img == "undefined" ? "" : picture_menu_json.list[0].img;
                    pmenu.name1 = typeof picture_menu_json.list[0].name == "undefined" ? "" : picture_menu_json.list[0].name;
                    pmenu.url1 = typeof picture_menu_json.list[0].url == "undefined" ? "" : picture_menu_json.list[0].url;

                    pmenu.img2 = typeof picture_menu_json.list[1].img == "undefined" ? "" : picture_menu_json.list[1].img;
                    pmenu.name2 = typeof picture_menu_json.list[1].name == "undefined" ? "" : picture_menu_json.list[1].name;
                    pmenu.url2 = typeof picture_menu_json.list[1].url == "undefined" ? "" : picture_menu_json.list[1].url;
                    pmenu.img3 = typeof picture_menu_json.list[2].img == "undefined" ? "" : picture_menu_json.list[2].img;
                    pmenu.name3 = typeof picture_menu_json.list[2].name == "undefined" ? "" : picture_menu_json.list[2].name;
                    pmenu.url3 = typeof picture_menu_json.list[2].url == "undefined" ? "" : picture_menu_json.list[2].url;
                    pmenu.img4 = typeof picture_menu_json.list[3].img == "undefined" ? "" : picture_menu_json.list[3].img;
                    pmenu.name4 = typeof picture_menu_json.list[3].name == "undefined" ? "" : picture_menu_json.list[3].name;
                    pmenu.url4 = typeof picture_menu_json.list[3].url == "undefined" ? "" : picture_menu_json.list[3].url;
                } else {
                    pmenu.img1 = "";
                    pmenu.name1 = "";
                    pmenu.url1 = "";
                    pmenu.img2 = "";
                    pmenu.name2 = "";
                    pmenu.url2 = "";
                    pmenu.img3 = "";
                    pmenu.name3 = "";
                    pmenu.url3 = "";
                    pmenu.img4 = "";
                    pmenu.name4 = "";
                    pmenu.url4 = "";
                }
                picture_menu.push(pmenu);
                $this.setData({
                    imgmenu3: picture_menu,
                    datalock: false
                });

                //活动图片
                var picture_menu2_str = globalset.picture_menu2;
                var picture_menu2_json = JSON.parse(picture_menu2_str);
                if (picture_menu2_json != undefined && picture_menu2_json.list != null && picture_menu2_json.list != undefined && typeof picture_menu2_json.list != undefined && picture_menu2_json.list != null && picture_menu2_json.list != '') {
                    $this.setData({
                        activitymenu: picture_menu2_json.list,
                        datalock: false
                    });

                }
                //广告图片
                var ad_menu_str = globalset.ad_menu;
                var ad_menu_json = JSON.parse(ad_menu_str);
                if (ad_menu_json != undefined && ad_menu_json.list != null && ad_menu_json.list != undefined && typeof ad_menu_json.list != undefined && ad_menu_json.list != null && ad_menu_json.list != '') {
                    $this.setData({
                        admenu: ad_menu_json.list,
                        datalock: false
                    });

                }
                $this.setData({
                    hiddenLoading: true
                });
                $this.getMember();

            }
        });

    },
    getMember: function () {
        var that = this;
        app.getUserInfo(function (userInfo) {
            //更新数据
            app.util.getUserInfo(function (response) {

                response.memberInfo.nickname = userInfo.nickName;
                response.memberInfo.avatar = userInfo.avatarUrl;
                response.memberInfo.city = userInfo.city;
                response.memberInfo.country = userInfo.country;
                response.memberInfo.province = userInfo.province;
                response.memberInfo.gender = userInfo.gender;
                that.addMember(response.memberInfo);
            });
        });
        // 页面渲染完成
    },
    //事件处理函数
    tabFun: function (e) {
        var $that = this;
        //获取触发事件组件的dataset属性  


        var _datasetId = e.target.dataset.id;
        if (_datasetId == 0) {
            if ($that.data.isShow0) {
                $that.setData({
                    isShow0: false,
                    isShow1: false,
                    isShow2: false,
                    curHdIndex: 3,
                })
            } else if (!$that.data.isShow0) {
                $that.setData({
                    isShow0: true,
                    isShow1: false,
                    isShow2: false,
                    curHdIndex: _datasetId,
                    redTriangle: true,
                })
            }

        } else if (_datasetId == 1) {
            if ($that.data.isShow1) {
                $that.setData({
                    isShow0: false,
                    isShow1: false,
                    isShow2: false,
                    curHdIndex: 3,
                })
            } else if (!$that.data.isShow1) {
                $that.setData({
                    isShow0: false,
                    isShow1: true,
                    isShow2: false,
                    curHdIndex: _datasetId,
                })
            }
        } else if (_datasetId == 2) {
            if ($that.data.isShow2) {
                $that.setData({
                    isShow0: false,
                    isShow1: false,
                    isShow2: false,
                    curHdIndex: 3,
                })
            } else if (!$that.data.isShow2) {
                $that.setData({
                    isShow0: false,
                    isShow1: false,
                    isShow2: true,
                    curHdIndex: _datasetId,
                })
            }
        }

    },
    addMember: function (userInfo) {
        var $this = this;
        app.util.request({
            url: 'entry/wxapp/AddMember',
            showLoading: false,
            data: {
                "m": 'nets_haojk',
                "from_uid": this.data.from_uid,
                "nickname": userInfo.nickname,
                "avatar": userInfo.avatar,
                "city": userInfo.city,
                "country": userInfo.country,
                "province": userInfo.province,
                "gender": userInfo.gender,
            },
            method: 'post',
            success: function (response) {
                //首页存储会员对象到缓存，其他页面直接读取缓存即可
                wx.setStorage({
                    key: "memberinfo",
                    data: response.data.data
                });
                $this.setData({
                    memberid: response.data.data.memberid,
                    nickname: response.data.data.nickname,
                    datalock: false
                });
                //取会员对象的方式
                wx.getStorage({
                    key: 'memberinfo',
                    success: function (res) {
                    }
                });
                if (typeof response.data.data.from_nickname != 'undefined' && response.data.data.from_nickname != '' && response.data.data.from_nickname != '无') {
                    wx.setNavigationBarTitle({
                        title: response.data.data.from_nickname + '的小店'//页面标题
                    });
                }
                if (typeof response.data.data.nickname != 'undefined' && response.data.data.nickname != '' && response.data.data.type == 1) {
                    wx.setNavigationBarTitle({
                        title: response.data.data.nickname + '的小店'//页面标题

                    });
                    $this.setData({
                        homeskinid: response.data.data.homeskinid,
                        datalock: false
                    });
                }
                if (typeof response.data.data.from_shopname != 'undefined' && response.data.data.from_shopname != '') {
                    wx.setNavigationBarTitle({
                        title: response.data.data.from_shopname//页面标题

                    });
                    $this.setData({
                        homeskinid: response.data.data.homeskinid,
                        datalock: false
                    });
                }
                if (typeof response.data.data.shopname != 'undefined' && response.data.data.shopname != '' && response.data.data.type == 1) {
                    wx.setNavigationBarTitle({
                        title: response.data.data.shopname//页面标题

                    });
                    $this.setData({
                        homeskinid: response.data.data.homeskinid,
                        datalock: false
                    });
                }
                $this.initIndex();

            }
        });
    },
    bysort: function (e) {
        var $this = this;
        //关闭下拉框
        if ($this.data.isShow2) {
            $this.setData({
                isShow0: false,
                isShow1: false,
                isShow2: false,
                curHdIndex: 3,
            })
        } else if (!$this.data.isShow2) {
            $this.setData({
                isShow0: false,
                isShow1: false,
                isShow2: false,
                curHdIndex: 3,

            })
        }
        wx.getSystemInfo({
            success: function (res) {
                $this.setData({
                    scrollHeight: res.windowHeight
                });
            }
        });
        this.setData({
            sort: e.currentTarget.dataset.sort
        });
        this.setData({
            commodity: [],
            datalock: false
        });
        this.goodList(1);
    },
    sign: function () {
        app.util.request({
            url: 'entry/wxapp/Sign',
            showLoading: false,
            data: {
                "m": 'nets_haojk'
            },
            method: 'post',
            success: function (response) {
                if (response.data.message == "") {
                    return;
                }
                //签到成功
                wx.showModal({
                    title: '签到成功',
                    content: response.data.message,
                    success: function (res) {

                    }
                });
            }
        });
    },
    bindChange: function (e) {
        var that = this;
        that.setData({ currentTab: e.detail.current });

    },

    swichNav: function (e) {
        var that = this;
        if (this.data.currentTab === e.target.dataset.current) {
            return false;
        } else {
            that.setData({
                currentTab: e.target.dataset.current
            });
        }
    },

    bycname: function (e) {

        var outappid = e.currentTarget.dataset.outurl;
        if (outappid != "" && outappid != undefined) {
            wx.navigateToMiniProgram({
                appId: outappid,
                path: '',
                extraData: {},
                envVersion: 'release',
                success(res) {
                    // 打开成功
                }
            })
        }
        var cname = e.currentTarget.dataset.url.split("=")[1];
        var cnametype = e.currentTarget.dataset.url.split("=")[2];
        var cnameid = e.currentTarget.dataset.url.split("=")[3];

        wx.setStorageSync("cname_show", e.currentTarget.dataset.cname);
        wx.setStorageSync("cname", cname);
        wx.setStorageSync("searchkey", "");
        //return;

        var thiscname = cname;


        thiscname.replace(/(^\s*)|(\s*$)/g, "");



        if (thiscname == "2小时跑单") {
            wx.navigateTo({
                url: "../seniorityTwohours/index",

            })

        } else if (thiscname == "砍价") {

            wx.navigateTo({
                url: "../shareFreeOrder/index",

            })

        } else if (cnametype == 3) {

            wx.navigateTo({
                url: "../tuiguangIndex/index?id=" + cnameid,
            })
        } else if (thiscname == "全天销售榜") {

            wx.navigateTo({
                url: "../seniorityAlldays/index",

            })

        } else if (thiscname == "拼购") {

            wx.switchTab({
                url: "../pingou/index",

            })

        } else if (thiscname == "实时排行榜" || thiscname == "榜单") {

            //  实时排行榜
            wx.reLaunch({
                url: "../seniority/index",

            })

        } else {
            wx.reLaunch({
                url: e.currentTarget.dataset.url
            })
        }


    },
    ////不跳转到精选页面
    bycname1: function (e) {
        var outappid = e.currentTarget.dataset.outurl;
        if (outappid != "" && outappid != undefined) {
            wx.navigateToMiniProgram({
                appId: outappid,
                path: '',
                extraData: {},
                envVersion: 'release',
                success(res) {
                    // 打开成功
                }
            });
            return;
        }
        var $this = this;

        var cname = e.currentTarget.dataset.url.split("=")[1];
        var cnametype = e.currentTarget.dataset.url.split("=")[2];
        var cnameid = e.currentTarget.dataset.url.split("=")[3];

        // wx.setStorageSync("cname_show", e.currentTarget.dataset.cname);
        // wx.setStorageSync("cname", cname);
        // wx.setStorageSync("searchkey", "");

        var thiscname = cname;


        thiscname.replace(/(^\s*)|(\s*$)/g, "");



        if (thiscname == "2小时跑单") {
            wx.navigateTo({
                url: "../seniorityTwohours/index",

            })

        } else if (thiscname == "砍价") {

            wx.navigateTo({
                url: "../shareFreeOrder/index",

            })

        } else if (cnametype == 3) {
            wx.navigateTo({
                url: "../tuiguangIndex/index?id=" + cnameid,
            })
        } else if (thiscname == "全天销售榜") {

            wx.navigateTo({
                url: "../seniorityAlldays/index",

            })

        } else if (thiscname == "拼购") {

            wx.switchTab({
                url: "../pingou/index",

            })

        } else if (thiscname == "实时排行榜" || thiscname == "榜单") {

            //  实时排行榜
            wx.reLaunch({
                url: "../seniority/index",

            })

        }


        wx.getSystemInfo({
            success: function (res) {
                $this.setData({
                    scrollHeight: res.windowHeight
                });
            }
        });

        //判断不为精选
        var cname = "";
        if (e.currentTarget.dataset.url) {

            cname = e.currentTarget.dataset.url.split("=")[1];
        }

        this.setData({
            cname_show: e.currentTarget.dataset.cname
        });

        //判断是否为精品请求
        if (e.currentTarget.dataset.isjinpin == 1) {

            this.setData({
                //给精选加背景

                cname: cname,
                uri: "list"
            });

        } else {
            this.setData({
                cname: cname,
                uri: "listbycname"
            });
        }



        this.setData({
            commodity: [],
            datalock: false
        });
        this.setData({
            keyword: ""
        });
        wx.setStorage({
            key: "cname",
            data: e.currentTarget.dataset.cname
        });
        wx.setStorage({
            key: "searchkey",
            data: ""
        });
        this.goodList(1);
    },
    searchkey: function (e) {
        wx.setStorageSync("searchkey", this.data.searchkey);
        wx.setStorageSync('limittime', '');
        wx.setStorageSync('realtime', '');

        if (this.data.searchkey != "") {
            wx.navigateTo({
                url: "../search/index",

            })
        } else {

        }




    },
    limittimeMore: function (e) {
        wx.setStorageSync("searchkey", "");
        wx.setStorageSync("limittime", 1);
        wx.setStorageSync("realtime", "");
        wx.navigateTo({
            url: "../search/index",
        })
    },
    realtimeMore: function (e) {
        wx.setStorageSync("searchkey", "");
        wx.setStorageSync("limittime", "");
        wx.setStorageSync("realtime", "1");
        wx.navigateTo({
            url: "../search/index",
        })
    },
    bindKeyInput: function (e) {
        var value = e.detail.value;
        var Expression = /http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/;
        var objExp = new RegExp(Expression);
        if (objExp.test(value) == true) {
            //是URL
            if (value.indexOf(".html") > 0) {
                value = value.split('?')[0];
                var valuearr = value.split("/");
                value = valuearr[valuearr.length - 1];
                value = value.replace(".html", "");
            }
            if (value.indexOf("sku=") > 0) {
                value = value.split('sku=')[1];
                var valuearr = value.split("&");
                value = valuearr[0];
            }
        }
        this.setData({
            searchkey: value
        });
        wx.setStorage({
            key: "searchkey",
            data: value
        });
        this.setData({
            keyword: value,
            cname: "",
            uri: "listbysearch"
        });
    },
    onShareAppMessage: function (res) {
        var memberinfo = wx.getStorageSync("memberinfo");
        if (res.from === 'button') {
            // 来自页面内转发按钮
        }

        return {
            title: this.data.globalset.title,
            path: '/haojk/pages/index/index?from_uid=' + memberinfo.memberid + '&from_nickname=' + memberinfo.nickname + '&type=' + memberinfo.type + '&homeskinid=' + memberinfo.homeskinid,
            success: function (res) {
                // 转发成功
            },
            fail: function (res) {
                // 转发失败
            }
        }

    },
    goTopFun: function (e) {
        var _top = this.data.scrollTop.scroll_top;//发现设置scroll-top值不能和上一次的值一样，否则无效，所以这里加了个判断 
        if (_top == 1) {
            _top = 0;
        } else {
            _top = 1;
        }
        this.setData({
            'scrollTop.scroll_top': _top
        });
    },
    judgeTem: function (e) {
    },
    goodList: function (page, t, callback, goodstype) {
        var $this = this;
        var limittime = 1;
        var realtime = 1;
        if (t == "limittime") {
            realtime = "";
        } else if (t == "realtime") {
            limittime = "";
        } else {
            //  $this.setData({canBottomRefresh:true});
            limittime = "";
            realtime = "";
        }
        if ($this.data.datalock) {
            //return false;
        }
        $this.setData({
            page: page,
            datalock: true,
        });

        app.util.request({
            url: 'entry/wxapp/Goods',
            showLoading: false,
            data: {
                m: 'nets_haojk',
                page: page,
                uri: $this.data.uri,
                limittime: limittime,
                realtime: realtime,
                sort: $this.data.sort,
                cname: $this.data.cname,
                minprice: $this.data.minprice,
                maxprice: $this.data.maxprice,
                goodstype: goodstype
            },
            method: 'post',
            success: function (response) {
                if (typeof callback == 'function') {
                    callback(response.data.data);
                    $this.setData({
                        datalock: false
                    });
                } else {
                    var goods = $this.data.commodity;
                    if (page == 1) {
                        goods = new Array();
                    }
                    var shishigoods = Array();
                    var jinrigoods = Array();
                    if (t == "limittime") {

                        goods = $this.data.goodCarousel;
                    } else if (t == "realtime") {
                        goods = $this.data.goodCarousel2;
                    }
                    if (response.data.data) {
                        var row = 0;
                        for (var i in response.data.data) {
                            row++;
                            if ($this.data.commission == 0) {
                                response.data.data[i].wlPrice_after1 = response.data.data[i].discount;
                            } else {
                                response.data.data[i].wlPrice_after1 = response.data.data[i].wlPrice_after * (response.data.data[i].wlCommissionShare / 100) * ($this.data.commission / 100) * 0.9;
                                if (response.data.data[i].wlPrice_after1 > 0)
                                    response.data.data[i].wlPrice_after1 = response.data.data[i].wlPrice_after1.toFixed(2);


                            }
                            if (row <= 6 && page == 1) {
                                shishigoods.push(response.data.data[i]);
                            } else if (row > 6 && row <= 12 && page == 1) {
                                jinrigoods.push(response.data.data[i]);
                            } else {
                                goods.push(response.data.data[i]);
                            }
                        }
                    }
                    if (t == "limittime") {
                        $this.setData({
                            goodCarousel: goods,
                            datalock: false
                        });
                    } else if (t == "realtime") {
                        $this.setData({
                            goodCarousel2: goods,
                            datalock: false
                        });

                    } else {
                        if (page == 1) {
                            $this.setData({
                                goodCarousel: shishigoods,
                                datalock: false
                            });

                            $this.setData({
                                goodCarousel2: jinrigoods,
                                datalock: false
                            });
                        }


                        $this.setData({
                            commodity: goods,
                            datalock: false
                        });


                    }
                }


            }
        });
    },

    //事件处理函数
    skiptodetail: function (e) {

        var skuId = e.currentTarget.dataset.skuid;
        for (var i = 0; i < this.data.commodity.length; i++) {
            if (this.data.commodity[i].skuId == skuId) {
                var good = this.data.commodity[i];
                wx.setStorage({
                    key: "good",
                    data: good
                });
            }
        }

        for (var i = 0; i < this.data.goodCarousel.length; i++) {
            if (this.data.goodCarousel[i].skuId == skuId) {
                var good = this.data.goodCarousel[i];
                wx.setStorage({
                    key: "good",
                    data: good
                });
            }
        }
        for (var i = 0; i < this.data.goodCarousel2.length; i++) {
            if (this.data.goodCarousel2[i].skuId == skuId) {
                var good = this.data.goodCarousel2[i];
                wx.setStorage({
                    key: "good",
                    data: good
                });
            }
        }





        wx.navigateTo({
            url: '../detail/index?skuId=' + skuId
        })
    },
    onReachBottom: function () {

        var $this = this;

        var page = $this.data.page + 1;
        var second_height = $this.data.second_height * page;
        $this.setData({ second_height: second_height });
        $this.goodList(page);

    },
    priceSort: function () {
        var $this = this;

        //关闭下拉框
        if ($this.data.isShow2) {
            $this.setData({
                isShow0: false,
                isShow1: false,
                isShow2: false,
                curHdIndex: 3,
            })
        } else if (!$this.data.isShow2) {
            $this.setData({
                isShow0: false,
                isShow1: false,
                isShow2: false,
                curHdIndex: 3,

            })
        }
        $this.goodList(1);
    },

    changeMaxprice: function (e) {
        this.setData({
            maxprice: e.detail.value
        })

    },
    changeMinprice: function (e) {
        this.setData({
            minprice: e.detail.value
        })

    },

    topDistance: function (e) {

        //    if(e.touches[0].clientY<0){
        //         this.setData({isFixed:true})
        //   }

    },
    showTanchuang: function () {
        var $that = this;
        app.util.request({
            url: 'entry/wxapp/GetOrderTipInfo',
            showLoading: false,
            data: {
                m: 'nets_haojk',

            },
            method: 'post',
            success: function (response) {

                if (response.data.errno == 0) {
                    var array = response.data.data;
                    var arrayLength = array.length;
                    var arrayI = Math.ceil(Math.random() * arrayLength);
                    var arrayItem = '';
                    setInterval(function () {
                        arrayI = Math.ceil(Math.random() * arrayLength);

                        arrayItem = array[arrayI];

                        $that.setData({ tipText: arrayItem });
                        if ($that.data.showAnimation) {
                            if (arrayItem) {
                                $that.setData({ showAnimation: false });
                            }

                        } else {
                            if (arrayItem) {
                                $that.setData({ showAnimation: true });
                            }

                        }

                    }, 8000)



                }
            }
        })










    },
    changePullDState: function () {

        var $that = this;
        if ($that.data.showPulldown) {
            $that.setData({
                showPulldown: false,
            })
        } else {
            $that.setData({
                showPulldown: true,
            })
        }

    }

})
